//
//  SN_Security_Controller.m
//  Shiyun_Newspaper
//
//  Created by zz on 17/6/27.
//  Copyright © 2017年 ShiYun. All rights reserved.
//

#import "SN_Security_Controller.h"

#import "SN_ChangePwd_Controller.h"
#import "SN_Identify_ViewController.h"
#import "SN_SetQuestionPwd_Controller.h"
#import "SN_ForgetAndEditPwd_Controller.h"

@interface SN_Security_Controller () <UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;



@end

@implementation SN_Security_Controller

#pragma mark -Getter
- (UITableView *)tableView {
    
    if (!_tableView) {
        
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, SafeAreaTopHeight, VIEW_WIDTH, VIEW_HEIGHT - SafeAreaTopHeight) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.scrollEnabled = false;
        UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, VIEW_HEIGHT)];
        footerView.backgroundColor = [UIColor colorWithHexString:@"#f4f5f7"];
        _tableView.tableFooterView = footerView;
        _tableView.rowHeight = 44;
        
    }
    
    return _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navBar.navigationItem.title = @"账号与安全";
    
    [self.view addSubview:self.tableView];
}

#pragma mark -UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 3;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [[UITableViewCell alloc] init];
    cell.textLabel.frame = CGRectMake(15, 14, 300, 16);
    cell.textLabel.font = [UIFont systemFontOfSize:16];
    cell.textLabel.textColor = [UIColor colorWithHexString:@"#3b3b3b"];
    
    switch (indexPath.row) {
        case 0:
            cell.textLabel.text = @"修改密码";
            break;
        case 1:
            cell.textLabel.text = @"修改绑定手机号";
            break;
        case 2:
            if ([SYAccountTool ShareAccount].account.szbpwd.length >= 4) {
                
                cell.textLabel.text = @"修改解题密码";
            }else {
            
                cell.textLabel.text = @"设置解题密码";
            }
        default:
            break;
    }
    
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

#pragma mark -UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row == 0) {
        
        SN_ChangePwd_Controller *vc = [[SN_ChangePwd_Controller alloc] init];
        vc.type = @"1";
        [self.navigationController pushViewController:vc animated:YES];
        
    }else if (indexPath.row == 1) {
    
        SN_Identify_ViewController *vc = [[SN_Identify_ViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 2) { //设置解题密码
        
        if ([SYAccountTool ShareAccount].account.szbpwd.length >= 4) { //修改解题密码
            
            SN_ForgetAndEditPwd_Controller *vc = [[SN_ForgetAndEditPwd_Controller alloc] init];
            vc.type  = 2;
            [self.navigationController pushViewController:vc animated:YES];
            
        }else {
        
        
            SN_SetQuestionPwd_Controller *vc = [[SN_SetQuestionPwd_Controller alloc] init];
            vc.type = QuestionPwdTypeSetting;
            [self.navigationController pushViewController:vc animated:YES];
        }
        
    }
    
}

@end
